/**
 * @author LKQ
 * @date 2022/2/18 16:01
 * @description 动态规划 dp[i] 为以第i个数字结尾的最长上升子序列长度，nums[i]必须被选取
 * dp[i] = max{dp[j]} + 1 其中，0<j<i并且nums[j] < nums[i]
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {4, 10, 4, 3, 8 ,9};
        System.out.println(solution.lengthOfLIS(nums));
    }
    public int lengthOfLIS(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int maxans = 1;
        for (int i = 1; i < nums.length; i++) {
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            maxans = Math.max(maxans, dp[i]);
        }
        return maxans;
    }
}
